<template>
  <div class="reportMistakeInfoAction el-card is-always-shadow el-card__body">
    <avue-crud
      ref="reportMondifyWaitSubmitCrud"
      :option="option"
      :table-loading="listLoading"
      :data="tableData"
      :page.sync="page"
      :search.sync="searchForm"
      @search-change="handleFilter"
      @selection-change="selectionChange">

      <!-- <template slot="menuLeft">
          <div style="padding-left: 350px;display:inline-block;">
            <span style="color: red;font-size: 13px">提示：报表差错提交之后，需在线网层级确认信息--报表差错更改--线网报表差错</span>
	    <br/><span style="color: red;font-size: 13px;padding-left: 37px;">更改通知菜单点击编辑按钮，将修改状态由修改中改为已完成。</span>
          </div>
      </template> -->
      <template slot="menuRight">
<!--        <el-button type="primary" size="mini" v-if="isShowLongPeriodSettlementBtn" @click="longZQJS()">长周期结算</el-button>-->
        <el-button type="primary" size="mini" @click="submitBomData()">提交</el-button>
        <el-button type="primary" size="mini" @click="exportExcel">导出</el-button>
      </template>
      <template slot="revenueTimeSearch" slot-scope="{row,size}">
        <div style="display: inline-flex;width: 320px">
            <el-date-picker
              v-model="searchForm.startRecordTime"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="开始日期">
            </el-date-picker>~
            <el-date-picker
              v-model="searchForm.endRecordTime"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="结束日期">
            </el-date-picker>
        </div>
      </template>
      <template slot="searchMenu" slot-scope="{row,size}">
        <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm)}" icon="el-icon-delete">清空</el-button>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button type="text" size="small" plain @click.stop="preview(scope.row)">预览</el-button>
      </template>
    </avue-crud>
<!--    <report-mistake-info-editor ref="reportMistakeInfoEditor" v-if="isShowReportMistakeInfoEditor"></report-mistake-info-editor>-->
    <preview ref="preview"></preview>
    <longZQJS ref="longZQJS"></longZQJS>
    <checkAccount ref="checkAccount" :params="{roleCode:'ZBZZ',isCheckRole:true}" @checkSubmitSuccess="checkSubmitSuccess"></checkAccount>
  </div>
</template>


<script>
    import {getForm, postForm} from '@/api/gen/gen'
    import ExportJsonExcel from "js-export-excel";
    import preview from './preview.vue';
    import longZQJS from './longZQJS.vue';
    import checkAccount from '../checkAccount.vue';
    import moment from 'moment';
    import {
      getgetStationCodes,
      getLineCodes, getStationByCode, isLongPeriodSettlement, setSearchFiledsEmpty
    } from "../../../../api/subwayRat/commonCheck";
    import {exportDataToExcel} from "../../../../api/subwayRat/exportSelf";
    import {
      get_sw_ck_data_submit_date,
      getXw_tvm_shouJieSuan_reportError_waitSubmit,
      getXw_tvm_shouJieSuan_waitSubmit,
      reportWaitSubmitMainOptionList,
      submit_Xw_tvm_data,
      submit_Xw_tvm_reportError_data,
    } from "../../../../api/stationTiecketManager/shouRuJieSuan/tvm/waitSubmitMain";
    export default {
      components:{preview,longZQJS,checkAccount
      },
      data() {
            return {
              row : {},
              listLoading: true,
              fileTemp:{},
              searchForm:{
                lineCode:'',
                stationCode:'',
                startRecordTime:"",
                endRecordTime:''
              },
              settleDateAll:{
                startSettleDate:'',
                endSettleDate:''
              },
              tableData:[],
              page: {
                total: 0, // 总页数
                currentPage: 1, // 当前页数
                pageSize: 20, // 每页显示多少条,
                isAsc: false// 是否倒序
              },
              attendancePerson:{
                attendancePersonId:'',
                attendancePersonJobNo:'',
                attendancePersonName:'',
              },//值班站长
              autoWidth: true,
              downloadLoading: false,
              isShowLongPeriodSettlementBtn:false,//是否展示长周期结算按钮
              multipleSelectionRows:[],
              multipleSelectionKeys:[],
              option:reportWaitSubmitMainOptionList(),
            }
        },
       async created() {
          if(this.$route.query.row){
            this.row = this.$route.query.row;
            debugger
            if(!this.row.submitLineCode && ! this.row.submitStationCode){
              this.row.submitLineCode = this.row.lineCode;
              this.row.submitStationCode = this.row.stationCode;
            }
            this.addContent('添加',0);
          }

          let lineCode=this.$store.getters.userInfo.lineCode;
          let stationCode=this.$store.getters.userInfo.stationCode;
          this.searchForm.lineCode=lineCode;
          this.searchForm.stationCode=stationCode;
          // //获取结算日期
          // let dates=await get_sw_ck_data_submit_date({lineCode:lineCode,stationCode:stationCode});
          // if(dates.data.data && dates.data.data.length>0){
          //   this.settleDateAll.startSettleDate=dates.data.data[0].startSettleDate;
          //   this.settleDateAll.endSettleDate=dates.data.data[0].endSettleDate;
          // }
          this.search();
        },
        methods: {
          moment,setSearchFiledsEmpty,
          async exportData(){ // 导出
            this.searchForm.pageNo=1;
            this.searchForm.pageSize=1000000000;
            if(this.selectKeys.length>0){
              exportDataToExcel(this.selectKeys,this.option.column,'TVM收入结算-报表修改待提交');
            }else {
              let res=await getXw_tvm_shouJieSuan_waitSubmit(this.searchForm);
              let data = res.data.data;
              exportDataToExcel(data,this.option.column,'TVM收入结算-报表修改待提交');
            }
          },
          search(){
            Object.assign(this.searchForm,this.$refs.reportMondifyWaitSubmitCrud.searchForm);
            Object.assign(this.searchForm,this.page);
            this.searchForm.userCode=this.$store.getters.userInfo.userCode;
            this.searchForm.lineCode=this.$store.getters.userInfo.lineCode;
            this.searchForm.stationCode=this.$store.getters.userInfo.stationCode;
            this.searchForm.is_report_settle_status=2; //等于2的情况
            this.searchForm.approvalStatus=0;
            getXw_tvm_shouJieSuan_reportError_waitSubmit(this.searchForm).then((res)=>{
              this.tableData=res.data.data;
              this.listLoading = false;
              this.page.total=res.data.total;
            });
          },
          longZQJS(){
            this.$nextTick(()=>{
              this.$refs.longZQJS.searchForm=this.searchForm;
              this.$refs.longZQJS.dialogVisible=true;
              this.$refs.longZQJS.search();
            });
          },
          preview(row){
              this.$nextTick(()=>{
                this.$refs.preview.search(row);
              });
          },
          checkSubmitSuccess(res,cab,callback){ //登录返回
            this.attendancePerson.attendancePersonJobNo=res;
            this.submitBomData(cab,callback);
          },
          handleSelectionChange(val,a){
            this.multipleSelectionRows=val;
            this.multipleSelectionKeys=[];
            for(let i=0;i<this.multipleSelectionRows.length;i++){
              this.multipleSelectionKeys.push(this.multipleSelectionRows[i].id);
            }
          },
          async exportExcel(){ // 导出
            let p={};
            Object.assign(p,this.searchForm);
            p.pageNo=1;
            p.pageSize=1000000000;
            if(this.multipleSelectionRows.length>0){
              exportDataToExcel(this.multipleSelectionRows,this.option.column,'tvm收入结算报表差错待提交');
            }else {
              let res=await getXw_tvm_shouJieSuan_reportError_waitSubmit(p);
              let data = res.data.data;
              exportDataToExcel(data,this.option.column,'tvm收入结算报表差错待提交');
            }
          },
          submitBomData(cab,callback){ //提交
            if(this.multipleSelectionRows.length<=0){
              this.$message.warning("请选择需要提交的数据！");
              return;
            }
            if(this.$refs.checkAccount.dialogVisibleAccountPassword==false){
              this.$refs.checkAccount.accountParamForm.account = '';
              this.$refs.checkAccount.accountParamForm.password = '';
              this.$refs.checkAccount.accountParamForm.token = '';
              this.$refs.checkAccount.dialogVisibleAccountPassword=true;
              this.$message.warning("请确认后可提交");
              return;
            }
            submit_Xw_tvm_reportError_data({rows:JSON.stringify(this.multipleSelectionRows),
              attendancePersonJobNo:this.attendancePerson.attendancePersonJobNo,
              startSettleDate:this.searchForm.startSettleDate,endSettleDate:this.searchForm.endSettleDate,
              lineCode:this.searchForm.lineCode,stationCode:this.searchForm.stationCode}).then(res=>{ //提交
              cab(res)
              // if(res.data.code==0){
              //   this.$message.success("操作成功");
              //   this.search();
              // }else{
              //   this.$message.error("操作失败");
              // }
              this.search();
            }).catch(error=> {
                callback(error)
                this.search();
                //this.$message.error("操作失败");
            })
          },
          selectionChange(list){
            this.multipleSelectionRows=list;
            this.multipleSelectionKeys=[];
            for(let i=0;i<list.length;i++){
              this.multipleSelectionKeys.push(list[i].id);
            }
          },
          handleFilter(params, done) {
            Object.assign(this.searchForm,params);
            this.search()
            done()
          },
        },
      mounted() {
        this.search();
        isLongPeriodSettlement({lineCode:this.$store.getters.userInfo.lineCode,stationCode:this.$store.getters.userInfo.stationCode}).then(res=>{
          this.isShowLongPeriodSettlementBtn=res.data.data;
        })
      }
    }
</script>
<style lang="scss">

</style>
